package com.augurit.gzcgwsp.webservice;

import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.augurit.gzcgwsp.commonex.util.lang.DateUtilsEX;
import com.augurit.gzcgwsp.ljzyz.web.form.YwYnBusinfoForm;

public class TestCardWebservice {

	/**
	 * 根据车辆信息创建xml
	 * @param form
	 * @return
	 */
	private static String ceateXml(String data){
			 Document docement=DocumentHelper.createDocument();
			 Element rootElement=docement.addElement("YwYnBusinfoForm");
			 rootElement.addElement("clbh").addText("AQ12301");
			 rootElement.addElement("cphm").addText("粤S20012");
			 rootElement.addElement("busId").addText(String.valueOf(21886));
			 rootElement.addElement("cjh").addText("1201211");
			 rootElement.addElement("fdjh").addText("25145144");
			 rootElement.addElement("gsmc").addText("广州test");
			 rootElement.addElement("qydj").addText("B级");
			 rootElement.addElement("carId").addText("21886");
			 rootElement.addElement("yxkssj").addText("2013-12-15");
			 rootElement.addElement("yxjssj").addText("2014-12-25");
		 return docement.asXML();
	}
	
	/**
	 * @param args
	 * @throws Exception
	 * @throws MalformedURLException
	 */
	public static String sendData(String data) throws MalformedURLException,Exception { 
		String url = "http://192.168.15.200/iccard/services/ICarDataService";
		String targetEendPoint = url;    
		String result="";
		try {
				Service  service = new Service();   
				Call call = (Call) service.createCall(); 
				call.setTargetEndpointAddress(new URL(targetEendPoint));
				//call.setUsername("test");
				//call.setPassword("test");
				Class<YwYnBusinfoForm> clazz = YwYnBusinfoForm.class; 
				QName qname=new QName(targetEendPoint, "saveCar");
		        call.setOperationName(qname); 
				call.setTargetEndpointAddress(new URL(targetEendPoint));
				String xml=ceateXml(data);
	            call.addParameter( "xml", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN); 
				call.setReturnType(org.apache.axis.Constants.XSD_STRING);
			    result =(String)call.invoke( new Object[] {xml});
				System.out.print(result);
		} catch (Exception e) {
			e.printStackTrace();
	}          
		return  result;
	}
	
	public static void main(String[] args) throws  Exception{
		TestCardWebservice.sendData("");
	}
}
